/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.spreedairy.portal.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import com.spreedairy.portal.NoSuchRecommendationException;
import com.spreedairy.portal.model.Recommendation;
import com.spreedairy.portal.model.impl.RecommendationImpl;
import com.spreedairy.portal.model.impl.RecommendationModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the recommendation service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author SpreeDairy
 * @see RecommendationPersistence
 * @see RecommendationUtil
 * @generated
 */
public class RecommendationPersistenceImpl extends BasePersistenceImpl<Recommendation>
	implements RecommendationPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link RecommendationUtil} to access the recommendation persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = RecommendationImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_FETCH_BY_USERID = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED,
			RecommendationImpl.class, FINDER_CLASS_NAME_ENTITY,
			"fetchByUserId",
			new String[] {
				Long.class.getName(), Long.class.getName(), Long.class.getName(),
				Long.class.getName()
			},
			RecommendationModelImpl.ITEMID_COLUMN_BITMASK |
			RecommendationModelImpl.USERID_COLUMN_BITMASK |
			RecommendationModelImpl.GROUPID_COLUMN_BITMASK |
			RecommendationModelImpl.COMPANYID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
			new String[] {
				Long.class.getName(), Long.class.getName(), Long.class.getName(),
				Long.class.getName()
			});
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED,
			RecommendationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByItemId",
			new String[] {
				Long.class.getName(), Long.class.getName(), Long.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID =
		new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED,
			RecommendationImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
			new String[] {
				Long.class.getName(), Long.class.getName(), Long.class.getName()
			},
			RecommendationModelImpl.ITEMID_COLUMN_BITMASK |
			RecommendationModelImpl.GROUPID_COLUMN_BITMASK |
			RecommendationModelImpl.COMPANYID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByItemId",
			new String[] {
				Long.class.getName(), Long.class.getName(), Long.class.getName()
			});
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED,
			RecommendationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED,
			RecommendationImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the recommendation in the entity cache if it is enabled.
	 *
	 * @param recommendation the recommendation
	 */
	public void cacheResult(Recommendation recommendation) {
		EntityCacheUtil.putResult(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationImpl.class, recommendation.getPrimaryKey(),
			recommendation);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
			new Object[] {
				Long.valueOf(recommendation.getItemId()),
				Long.valueOf(recommendation.getUserId()),
				Long.valueOf(recommendation.getGroupId()),
				Long.valueOf(recommendation.getCompanyId())
			}, recommendation);

		recommendation.resetOriginalValues();
	}

	/**
	 * Caches the recommendations in the entity cache if it is enabled.
	 *
	 * @param recommendations the recommendations
	 */
	public void cacheResult(List<Recommendation> recommendations) {
		for (Recommendation recommendation : recommendations) {
			if (EntityCacheUtil.getResult(
						RecommendationModelImpl.ENTITY_CACHE_ENABLED,
						RecommendationImpl.class, recommendation.getPrimaryKey()) == null) {
				cacheResult(recommendation);
			}
			else {
				recommendation.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all recommendations.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(RecommendationImpl.class.getName());
		}

		EntityCacheUtil.clearCache(RecommendationImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the recommendation.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(Recommendation recommendation) {
		EntityCacheUtil.removeResult(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationImpl.class, recommendation.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache(recommendation);
	}

	@Override
	public void clearCache(List<Recommendation> recommendations) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (Recommendation recommendation : recommendations) {
			EntityCacheUtil.removeResult(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
				RecommendationImpl.class, recommendation.getPrimaryKey());

			clearUniqueFindersCache(recommendation);
		}
	}

	protected void clearUniqueFindersCache(Recommendation recommendation) {
		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
			new Object[] {
				Long.valueOf(recommendation.getItemId()),
				Long.valueOf(recommendation.getUserId()),
				Long.valueOf(recommendation.getGroupId()),
				Long.valueOf(recommendation.getCompanyId())
			});
	}

	/**
	 * Creates a new recommendation with the primary key. Does not add the recommendation to the database.
	 *
	 * @param recommendationId the primary key for the new recommendation
	 * @return the new recommendation
	 */
	public Recommendation create(long recommendationId) {
		Recommendation recommendation = new RecommendationImpl();

		recommendation.setNew(true);
		recommendation.setPrimaryKey(recommendationId);

		return recommendation;
	}

	/**
	 * Removes the recommendation with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param recommendationId the primary key of the recommendation
	 * @return the recommendation that was removed
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation remove(long recommendationId)
		throws NoSuchRecommendationException, SystemException {
		return remove(Long.valueOf(recommendationId));
	}

	/**
	 * Removes the recommendation with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the recommendation
	 * @return the recommendation that was removed
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Recommendation remove(Serializable primaryKey)
		throws NoSuchRecommendationException, SystemException {
		Session session = null;

		try {
			session = openSession();

			Recommendation recommendation = (Recommendation)session.get(RecommendationImpl.class,
					primaryKey);

			if (recommendation == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchRecommendationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(recommendation);
		}
		catch (NoSuchRecommendationException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected Recommendation removeImpl(Recommendation recommendation)
		throws SystemException {
		recommendation = toUnwrappedModel(recommendation);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, recommendation);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(recommendation);

		return recommendation;
	}

	@Override
	public Recommendation updateImpl(
		com.spreedairy.portal.model.Recommendation recommendation, boolean merge)
		throws SystemException {
		recommendation = toUnwrappedModel(recommendation);

		boolean isNew = recommendation.isNew();

		RecommendationModelImpl recommendationModelImpl = (RecommendationModelImpl)recommendation;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, recommendation, merge);

			recommendation.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !RecommendationModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((recommendationModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(recommendationModelImpl.getOriginalItemId()),
						Long.valueOf(recommendationModelImpl.getOriginalGroupId()),
						Long.valueOf(recommendationModelImpl.getOriginalCompanyId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
					args);

				args = new Object[] {
						Long.valueOf(recommendationModelImpl.getItemId()),
						Long.valueOf(recommendationModelImpl.getGroupId()),
						Long.valueOf(recommendationModelImpl.getCompanyId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
					args);
			}
		}

		EntityCacheUtil.putResult(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
			RecommendationImpl.class, recommendation.getPrimaryKey(),
			recommendation);

		if (isNew) {
			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
				new Object[] {
					Long.valueOf(recommendation.getItemId()),
					Long.valueOf(recommendation.getUserId()),
					Long.valueOf(recommendation.getGroupId()),
					Long.valueOf(recommendation.getCompanyId())
				}, recommendation);
		}
		else {
			if ((recommendationModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(recommendationModelImpl.getOriginalItemId()),
						Long.valueOf(recommendationModelImpl.getOriginalUserId()),
						Long.valueOf(recommendationModelImpl.getOriginalGroupId()),
						Long.valueOf(recommendationModelImpl.getOriginalCompanyId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID, args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
					new Object[] {
						Long.valueOf(recommendation.getItemId()),
						Long.valueOf(recommendation.getUserId()),
						Long.valueOf(recommendation.getGroupId()),
						Long.valueOf(recommendation.getCompanyId())
					}, recommendation);
			}
		}

		return recommendation;
	}

	protected Recommendation toUnwrappedModel(Recommendation recommendation) {
		if (recommendation instanceof RecommendationImpl) {
			return recommendation;
		}

		RecommendationImpl recommendationImpl = new RecommendationImpl();

		recommendationImpl.setNew(recommendation.isNew());
		recommendationImpl.setPrimaryKey(recommendation.getPrimaryKey());

		recommendationImpl.setRecommendationId(recommendation.getRecommendationId());
		recommendationImpl.setItemId(recommendation.getItemId());
		recommendationImpl.setUserId(recommendation.getUserId());
		recommendationImpl.setGroupId(recommendation.getGroupId());
		recommendationImpl.setCompanyId(recommendation.getCompanyId());
		recommendationImpl.setCreateDate(recommendation.getCreateDate());

		return recommendationImpl;
	}

	/**
	 * Returns the recommendation with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the recommendation
	 * @return the recommendation
	 * @throws com.liferay.portal.NoSuchModelException if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Recommendation findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the recommendation with the primary key or throws a {@link com.spreedairy.portal.NoSuchRecommendationException} if it could not be found.
	 *
	 * @param recommendationId the primary key of the recommendation
	 * @return the recommendation
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation findByPrimaryKey(long recommendationId)
		throws NoSuchRecommendationException, SystemException {
		Recommendation recommendation = fetchByPrimaryKey(recommendationId);

		if (recommendation == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + recommendationId);
			}

			throw new NoSuchRecommendationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				recommendationId);
		}

		return recommendation;
	}

	/**
	 * Returns the recommendation with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the recommendation
	 * @return the recommendation, or <code>null</code> if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Recommendation fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the recommendation with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param recommendationId the primary key of the recommendation
	 * @return the recommendation, or <code>null</code> if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation fetchByPrimaryKey(long recommendationId)
		throws SystemException {
		Recommendation recommendation = (Recommendation)EntityCacheUtil.getResult(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
				RecommendationImpl.class, recommendationId);

		if (recommendation == _nullRecommendation) {
			return null;
		}

		if (recommendation == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				recommendation = (Recommendation)session.get(RecommendationImpl.class,
						Long.valueOf(recommendationId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (recommendation != null) {
					cacheResult(recommendation);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(RecommendationModelImpl.ENTITY_CACHE_ENABLED,
						RecommendationImpl.class, recommendationId,
						_nullRecommendation);
				}

				closeSession(session);
			}
		}

		return recommendation;
	}

	/**
	 * Returns the recommendation where itemId = &#63; and userId = &#63; and groupId = &#63; and companyId = &#63; or throws a {@link com.spreedairy.portal.NoSuchRecommendationException} if it could not be found.
	 *
	 * @param itemId the item ID
	 * @param userId the user ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @return the matching recommendation
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation findByUserId(long itemId, long userId, long groupId,
		long companyId) throws NoSuchRecommendationException, SystemException {
		Recommendation recommendation = fetchByUserId(itemId, userId, groupId,
				companyId);

		if (recommendation == null) {
			StringBundler msg = new StringBundler(10);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("itemId=");
			msg.append(itemId);

			msg.append(", userId=");
			msg.append(userId);

			msg.append(", groupId=");
			msg.append(groupId);

			msg.append(", companyId=");
			msg.append(companyId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchRecommendationException(msg.toString());
		}

		return recommendation;
	}

	/**
	 * Returns the recommendation where itemId = &#63; and userId = &#63; and groupId = &#63; and companyId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param itemId the item ID
	 * @param userId the user ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @return the matching recommendation, or <code>null</code> if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation fetchByUserId(long itemId, long userId, long groupId,
		long companyId) throws SystemException {
		return fetchByUserId(itemId, userId, groupId, companyId, true);
	}

	/**
	 * Returns the recommendation where itemId = &#63; and userId = &#63; and groupId = &#63; and companyId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param itemId the item ID
	 * @param userId the user ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching recommendation, or <code>null</code> if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation fetchByUserId(long itemId, long userId, long groupId,
		long companyId, boolean retrieveFromCache) throws SystemException {
		Object[] finderArgs = new Object[] { itemId, userId, groupId, companyId };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
					finderArgs, this);
		}

		if (result instanceof Recommendation) {
			Recommendation recommendation = (Recommendation)result;

			if ((itemId != recommendation.getItemId()) ||
					(userId != recommendation.getUserId()) ||
					(groupId != recommendation.getGroupId()) ||
					(companyId != recommendation.getCompanyId())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(5);

			query.append(_SQL_SELECT_RECOMMENDATION_WHERE);

			query.append(_FINDER_COLUMN_USERID_ITEMID_2);

			query.append(_FINDER_COLUMN_USERID_USERID_2);

			query.append(_FINDER_COLUMN_USERID_GROUPID_2);

			query.append(_FINDER_COLUMN_USERID_COMPANYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(itemId);

				qPos.add(userId);

				qPos.add(groupId);

				qPos.add(companyId);

				List<Recommendation> list = q.list();

				result = list;

				Recommendation recommendation = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
						finderArgs, list);
				}
				else {
					recommendation = list.get(0);

					cacheResult(recommendation);

					if ((recommendation.getItemId() != itemId) ||
							(recommendation.getUserId() != userId) ||
							(recommendation.getGroupId() != groupId) ||
							(recommendation.getCompanyId() != companyId)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
							finderArgs, recommendation);
					}
				}

				return recommendation;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (Recommendation)result;
			}
		}
	}

	/**
	 * Returns all the recommendations where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @return the matching recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public List<Recommendation> findByItemId(long itemId, long groupId,
		long companyId) throws SystemException {
		return findByItemId(itemId, groupId, companyId, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the recommendations where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param start the lower bound of the range of recommendations
	 * @param end the upper bound of the range of recommendations (not inclusive)
	 * @return the range of matching recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public List<Recommendation> findByItemId(long itemId, long groupId,
		long companyId, int start, int end) throws SystemException {
		return findByItemId(itemId, groupId, companyId, start, end, null);
	}

	/**
	 * Returns an ordered range of all the recommendations where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param start the lower bound of the range of recommendations
	 * @param end the upper bound of the range of recommendations (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public List<Recommendation> findByItemId(long itemId, long groupId,
		long companyId, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
			finderArgs = new Object[] { itemId, groupId, companyId };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
			finderArgs = new Object[] {
					itemId, groupId, companyId,
					
					start, end, orderByComparator
				};
		}

		List<Recommendation> list = (List<Recommendation>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if ((list != null) && !list.isEmpty()) {
			for (Recommendation recommendation : list) {
				if ((itemId != recommendation.getItemId()) ||
						(groupId != recommendation.getGroupId()) ||
						(companyId != recommendation.getCompanyId())) {
					list = null;

					break;
				}
			}
		}

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(5 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(4);
			}

			query.append(_SQL_SELECT_RECOMMENDATION_WHERE);

			query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);

			query.append(_FINDER_COLUMN_ITEMID_GROUPID_2);

			query.append(_FINDER_COLUMN_ITEMID_COMPANYID_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(itemId);

				qPos.add(groupId);

				qPos.add(companyId);

				list = (List<Recommendation>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first recommendation in the ordered set where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching recommendation
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation findByItemId_First(long itemId, long groupId,
		long companyId, OrderByComparator orderByComparator)
		throws NoSuchRecommendationException, SystemException {
		Recommendation recommendation = fetchByItemId_First(itemId, groupId,
				companyId, orderByComparator);

		if (recommendation != null) {
			return recommendation;
		}

		StringBundler msg = new StringBundler(8);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("itemId=");
		msg.append(itemId);

		msg.append(", groupId=");
		msg.append(groupId);

		msg.append(", companyId=");
		msg.append(companyId);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchRecommendationException(msg.toString());
	}

	/**
	 * Returns the first recommendation in the ordered set where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching recommendation, or <code>null</code> if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation fetchByItemId_First(long itemId, long groupId,
		long companyId, OrderByComparator orderByComparator)
		throws SystemException {
		List<Recommendation> list = findByItemId(itemId, groupId, companyId, 0,
				1, orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the last recommendation in the ordered set where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching recommendation
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation findByItemId_Last(long itemId, long groupId,
		long companyId, OrderByComparator orderByComparator)
		throws NoSuchRecommendationException, SystemException {
		Recommendation recommendation = fetchByItemId_Last(itemId, groupId,
				companyId, orderByComparator);

		if (recommendation != null) {
			return recommendation;
		}

		StringBundler msg = new StringBundler(8);

		msg.append(_NO_SUCH_ENTITY_WITH_KEY);

		msg.append("itemId=");
		msg.append(itemId);

		msg.append(", groupId=");
		msg.append(groupId);

		msg.append(", companyId=");
		msg.append(companyId);

		msg.append(StringPool.CLOSE_CURLY_BRACE);

		throw new NoSuchRecommendationException(msg.toString());
	}

	/**
	 * Returns the last recommendation in the ordered set where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching recommendation, or <code>null</code> if a matching recommendation could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation fetchByItemId_Last(long itemId, long groupId,
		long companyId, OrderByComparator orderByComparator)
		throws SystemException {
		int count = countByItemId(itemId, groupId, companyId);

		List<Recommendation> list = findByItemId(itemId, groupId, companyId,
				count - 1, count, orderByComparator);

		if (!list.isEmpty()) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * Returns the recommendations before and after the current recommendation in the ordered set where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param recommendationId the primary key of the current recommendation
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next recommendation
	 * @throws com.spreedairy.portal.NoSuchRecommendationException if a recommendation with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation[] findByItemId_PrevAndNext(long recommendationId,
		long itemId, long groupId, long companyId,
		OrderByComparator orderByComparator)
		throws NoSuchRecommendationException, SystemException {
		Recommendation recommendation = findByPrimaryKey(recommendationId);

		Session session = null;

		try {
			session = openSession();

			Recommendation[] array = new RecommendationImpl[3];

			array[0] = getByItemId_PrevAndNext(session, recommendation, itemId,
					groupId, companyId, orderByComparator, true);

			array[1] = recommendation;

			array[2] = getByItemId_PrevAndNext(session, recommendation, itemId,
					groupId, companyId, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Recommendation getByItemId_PrevAndNext(Session session,
		Recommendation recommendation, long itemId, long groupId,
		long companyId, OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_RECOMMENDATION_WHERE);

		query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);

		query.append(_FINDER_COLUMN_ITEMID_GROUPID_2);

		query.append(_FINDER_COLUMN_ITEMID_COMPANYID_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(itemId);

		qPos.add(groupId);

		qPos.add(companyId);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(recommendation);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<Recommendation> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the recommendations.
	 *
	 * @return the recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public List<Recommendation> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the recommendations.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of recommendations
	 * @param end the upper bound of the range of recommendations (not inclusive)
	 * @return the range of recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public List<Recommendation> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the recommendations.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of recommendations
	 * @param end the upper bound of the range of recommendations (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public List<Recommendation> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<Recommendation> list = (List<Recommendation>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_RECOMMENDATION);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_RECOMMENDATION;
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<Recommendation>)QueryUtil.list(q,
							getDialect(), start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<Recommendation>)QueryUtil.list(q,
							getDialect(), start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes the recommendation where itemId = &#63; and userId = &#63; and groupId = &#63; and companyId = &#63; from the database.
	 *
	 * @param itemId the item ID
	 * @param userId the user ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @return the recommendation that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public Recommendation removeByUserId(long itemId, long userId,
		long groupId, long companyId)
		throws NoSuchRecommendationException, SystemException {
		Recommendation recommendation = findByUserId(itemId, userId, groupId,
				companyId);

		return remove(recommendation);
	}

	/**
	 * Removes all the recommendations where itemId = &#63; and groupId = &#63; and companyId = &#63; from the database.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByItemId(long itemId, long groupId, long companyId)
		throws SystemException {
		for (Recommendation recommendation : findByItemId(itemId, groupId,
				companyId)) {
			remove(recommendation);
		}
	}

	/**
	 * Removes all the recommendations from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (Recommendation recommendation : findAll()) {
			remove(recommendation);
		}
	}

	/**
	 * Returns the number of recommendations where itemId = &#63; and userId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param userId the user ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @return the number of matching recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public int countByUserId(long itemId, long userId, long groupId,
		long companyId) throws SystemException {
		Object[] finderArgs = new Object[] { itemId, userId, groupId, companyId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(5);

			query.append(_SQL_COUNT_RECOMMENDATION_WHERE);

			query.append(_FINDER_COLUMN_USERID_ITEMID_2);

			query.append(_FINDER_COLUMN_USERID_USERID_2);

			query.append(_FINDER_COLUMN_USERID_GROUPID_2);

			query.append(_FINDER_COLUMN_USERID_COMPANYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(itemId);

				qPos.add(userId);

				qPos.add(groupId);

				qPos.add(companyId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of recommendations where itemId = &#63; and groupId = &#63; and companyId = &#63;.
	 *
	 * @param itemId the item ID
	 * @param groupId the group ID
	 * @param companyId the company ID
	 * @return the number of matching recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public int countByItemId(long itemId, long groupId, long companyId)
		throws SystemException {
		Object[] finderArgs = new Object[] { itemId, groupId, companyId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(4);

			query.append(_SQL_COUNT_RECOMMENDATION_WHERE);

			query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);

			query.append(_FINDER_COLUMN_ITEMID_GROUPID_2);

			query.append(_FINDER_COLUMN_ITEMID_COMPANYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(itemId);

				qPos.add(groupId);

				qPos.add(companyId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of recommendations.
	 *
	 * @return the number of recommendations
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_RECOMMENDATION);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the recommendation persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.spreedairy.portal.model.Recommendation")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<Recommendation>> listenersList = new ArrayList<ModelListener<Recommendation>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<Recommendation>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(RecommendationImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = CustomFieldPersistence.class)
	protected CustomFieldPersistence customFieldPersistence;
	@BeanReference(type = CustomFieldValuePersistence.class)
	protected CustomFieldValuePersistence customFieldValuePersistence;
	@BeanReference(type = RecommendationPersistence.class)
	protected RecommendationPersistence recommendationPersistence;
	@BeanReference(type = WishlistPersistence.class)
	protected WishlistPersistence wishlistPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_RECOMMENDATION = "SELECT recommendation FROM Recommendation recommendation";
	private static final String _SQL_SELECT_RECOMMENDATION_WHERE = "SELECT recommendation FROM Recommendation recommendation WHERE ";
	private static final String _SQL_COUNT_RECOMMENDATION = "SELECT COUNT(recommendation) FROM Recommendation recommendation";
	private static final String _SQL_COUNT_RECOMMENDATION_WHERE = "SELECT COUNT(recommendation) FROM Recommendation recommendation WHERE ";
	private static final String _FINDER_COLUMN_USERID_ITEMID_2 = "recommendation.itemId = ? AND ";
	private static final String _FINDER_COLUMN_USERID_USERID_2 = "recommendation.userId = ? AND ";
	private static final String _FINDER_COLUMN_USERID_GROUPID_2 = "recommendation.groupId = ? AND ";
	private static final String _FINDER_COLUMN_USERID_COMPANYID_2 = "recommendation.companyId = ?";
	private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "recommendation.itemId = ? AND ";
	private static final String _FINDER_COLUMN_ITEMID_GROUPID_2 = "recommendation.groupId = ? AND ";
	private static final String _FINDER_COLUMN_ITEMID_COMPANYID_2 = "recommendation.companyId = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "recommendation.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Recommendation exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Recommendation exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(RecommendationPersistenceImpl.class);
	private static Recommendation _nullRecommendation = new RecommendationImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<Recommendation> toCacheModel() {
				return _nullRecommendationCacheModel;
			}
		};

	private static CacheModel<Recommendation> _nullRecommendationCacheModel = new CacheModel<Recommendation>() {
			public Recommendation toEntityModel() {
				return _nullRecommendation;
			}
		};
}